<template>
  <div class="box">
    <RenderTable
      :superQueryFieldList="superQueryFieldList"
      :queryParamArr="queryParamArr"
      :defColumns="defColumns"
      :url="url"
      :isShowRowSelection="true"
      :defaultParams="defaultParams"
      :isUseStatusTemp="false"
      @handleEdit="handleEdit"
      @onSelectChange="tableSelectChange"
      ref="renderTable"
    >
      <div slot="btn" style="padding-bottom: 10px">
        <p-button type="primary" @click="showAddModal">新增</p-button>
        <p-button
          type="primary"
          :disabled="selectionRows.length == 0"
          style="margin-left: 10px"
          @click="submit"
          >提交</p-button
        >
      </div>

      <template v-slot:action="{ record }">
        <a @click="handleEdit(record)">编辑</a>
        <p-divider type="vertical" />

        <p-popconfirm
          title="确定删除吗?"
          @confirm="() => $refs.renderTable.handleDelete(record.id)"
        >
          <a>删除</a>
        </p-popconfirm>
      </template>
    </RenderTable>

    <IndexModal ref="indexModal" @handleSuccess="handleSuccess"></IndexModal>
  </div>
</template>

<script type="text/javascript">
import RenderTable from "@/components/renderTable";
import IndexModal from "./modules/indexModal.vue";
import { getDictItemsArr } from "@/utils/util";
import { timestampToDatetime } from "@/utils/util";
import { postAction, putAction, getAction, api } from "@/api/manage";

const superQueryFieldList = [
  {
    value: "remark",
    text: "备注",
    type: "String",
  },
];
export default {
  data() {
    return {
      superQueryFieldList,
      queryParamArr: [
        {
          label: "申请编号",
          placeholder: "请输入申请编号",
          type: "input",
          key: "applyNo",
          value: "",
        },
      ],
      defColumns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: (t, r, index) => {
            return parseInt(index) + 1;
          },
        },
        {
          title: "申请编号",
          align: "center",
          dataIndex: "applyNo",
        },
        {
          title: "申请部门",
          align: "center",
          dataIndex: "deptname",
        },
        {
          title: "需求人数",
          align: "center",
          dataIndex: "needMembers",
        },
        {
          title: "创建人",
          align: "center",
          dataIndex: "createBy",
        },
        {
          title: "创建日期",
          align: "center",
          dataIndex: "createTime",
          customRender: (t, r, index) => {
            return timestampToDatetime(t);
          },
        },
        {
          title: "流程状态",
          align: "center",
          dataIndex: "status",
          customRender: (t, r, index) => {
            return {
              0: "待提交",
              1: "待中试工艺部提交",
              2: "待生产制造部提交",
              3: "审批中",
              4: "事业部经理审批",
              5: "制造部总经理审批",
              6: "被驳回",
              7: "终止",
              8: "发行",
            }[t];
          },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: "action" },
        },
      ],
      defaultParams: {
        type: 3,
      },
      // table 选中的项
      selectionRows: [],
      // 假期分类数字字典
      holidayTypeKeys: {},
      url: {
        list: "/mes-manpower/mesHrManpowerLendoutApply/list",
        delete: "/mes-manpower/mesHrManpowerLendoutApply",
        submit: "/mes-manpower/mesHrManpowerLendoutApply/submit", // 提交
      },

      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
      },
    };
  },
  mounted() {
    this.getAjaxGetDictItems();
  },
  methods: {
    // 获取数字字典
    getAjaxGetDictItems() {
      const arr = [{ code: "mes_holiday_type", key: "holidayTypeKeys" }];
      getDictItemsArr(this, arr);
    },

    // table 选中改变
    tableSelectChange(selectionRows) {
      this.selectionRows = selectionRows;
    },

    handleEdit(record) {
      this.$refs.indexModal.showModal(record);
    },
    // 显示新增弹窗
    showAddModal() {
      this.$refs.indexModal.showModal();
    },
    handleSuccess() {
      this.$refs.renderTable.loadData();
    },
    // 提交
    submit(){
      const param = {
        id: this.selectionRows[0].id
      }
      getAction(this.url.submit, param).then((res) => {
        if (res.success) {
          this.$message.success('提交成功')
          this.$refs.renderTable.loadData()
        }else {
          this.$message.error(res.msg);
        }
      });      
    }
  },
  components: {
    RenderTable,
    IndexModal,
  },
};
</script>

<style lang="less" scoped>
</style>


